<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/17
 * Time: 19:14
 */
namespace Service;

use App\Article;
use App\ArticleComments;
use App\Notifications\ReplyNotification;
use App\User;

class ArticleService{
    /**
     *
     * @param Article $article
     * @return bool
     */
    public static function publishArticle(Article $article){
        try {
            return $article->save();
        }catch(\Exception $e){
            throw $e;
        }
    }

    public static function postComment(Article $article, ArticleComments $oneComment, User $user){
        try {
            $succ = $oneComment->save();
            if ($succ) {
                $user->notify(new ReplyNotification($article));
            }
            return $succ;
        }catch(\Exception $e){
            throw $e;
        }
    }

    public static function isHisComment(ArticleComments $comment, User $user){
        return $user->id == $comment->user_id;
    }

    public static function isHisArticle(Article $article, User $user){
        return $user->id == $article->user_id;
    }
}
